﻿Public Class frmCadastroCargoFuncao
    Private cargo As New _cargoFuncao
    Private _modoJanela As String
    Private _idCargoFuncao As Integer
    Private _DsCargoFuncao As String

    Private Sub setCargoFuncao()
        With cargo
            If txtIdCargo.Text = String.Empty Then
                .idCargofuncao = 0
            Else
                .idCargofuncao = txtIdCargo.Text
            End If
            .dsCargoFuncao = txtdsCargoFuncao.Text
        End With

    End Sub
    Private Sub getCargoFuncao()
        With cargo
            txtIdCargo.Text = .idCargofuncao
            txtdsCargoFuncao.Text = .dsCargoFuncao
        End With
    End Sub
    Private Sub limpaForm()
        txtIdCargo.Text = ""
        txtdsCargoFuncao.Text = ""
    End Sub

    Public Sub New(ByVal pModoJanela As String, _
                   ByVal pIdCargoFuncao As Integer, _
                   ByVal pDsCargoFuncao As String)
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        _modoJanela = pModoJanela
        _idCargoFuncao = pIdCargoFuncao
        _DsCargoFuncao = pDsCargoFuncao

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub frmCadastroCargoFuncao_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If _modoJanela = "Inserir" Then
            txtIdCargo.Text = ""
            txtdsCargoFuncao.Text = ""
        End If
        If _modoJanela = "Alterar" Then
            txtIdCargo.Text = _idCargoFuncao
            txtdsCargoFuncao.Text = _DsCargoFuncao
        End If
    End Sub

    Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalvar.Click
        setCargoFuncao()
        If _modoJanela = "Inserir" Then
            cargo.insereCargoFuncao()
            If MsgBox("Cargo cadastrado com sucesso, deseja cadastrar outro?", MsgBoxStyle.YesNo, "SIMO") = MsgBoxResult.Yes Then
                limpaForm()
                txtdsCargoFuncao.Focus()
                Me.DialogResult = Windows.Forms.DialogResult.OK
            Else
                Me.Close()
            End If
        End If

        If _modoJanela = "Alterar" Then
            cargo.alteraCargoFuncao()
            MsgBox("Cargo ou função alterado com sucesso com sucesso")
            Me.Close()
        End If
    End Sub
End Class